package com.ruoyi.web.controller.shopping;

import java.util.List;

import com.ruoyi.system.service.IGoodviceService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Goodvice;
import com.ruoyi.framework.web.base.BaseController;
import com.ruoyi.common.page.TableDataInfo;
import com.ruoyi.common.base.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 商品副属性 信息操作处理
 * 
 * @author ruoyi
 * @date 2019-07-16
 */
@Controller
@RequestMapping("/system/goodvice")
public class GoodviceController extends BaseController
{
    private String prefix = "system/goodvice";
	
	@Autowired
	private IGoodviceService goodviceService;
	
	@RequiresPermissions("system:goodvice:view")
	@GetMapping()
	public String goodvice()
	{
	    return prefix + "/goodvice";
	}
	
	/**
	 * 查询商品副属性列表
	 */
	@RequiresPermissions("system:goodvice:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(Goodvice goodvice)
	{
		startPage();
        List<Goodvice> list = goodviceService.selectGoodviceList(goodvice);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出商品副属性列表
	 */
	@RequiresPermissions("system:goodvice:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Goodvice goodvice)
    {
    	List<Goodvice> list = goodviceService.selectGoodviceList(goodvice);
        ExcelUtil<Goodvice> util = new ExcelUtil<Goodvice>(Goodvice.class);
        return util.exportExcel(list, "goodvice");
    }
	
	/**
	 * 新增商品副属性
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存商品副属性
	 */
	@RequiresPermissions("system:goodvice:add")
	@Log(title = "商品副属性", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(Goodvice goodvice)
	{		
		return toAjax(goodviceService.insertGoodvice(goodvice));
	}

	/**
	 * 修改商品副属性
	 */
	@GetMapping("/edit/{goodVice}")
	public String edit(@PathVariable("goodVice") Integer goodVice, ModelMap mmap)
	{
		Goodvice goodvice = goodviceService.selectGoodviceById(goodVice);
		mmap.put("goodvice", goodvice);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存商品副属性
	 */
	@RequiresPermissions("system:goodvice:edit")
	@Log(title = "商品副属性", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(Goodvice goodvice)
	{		
		return toAjax(goodviceService.updateGoodvice(goodvice));
	}
	
	/**
	 * 删除商品副属性
	 */
	@RequiresPermissions("system:goodvice:remove")
	@Log(title = "商品副属性", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(goodviceService.deleteGoodviceByIds(ids));
	}
	
}
